<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">

	<ui:define name="corpoForm">
		
		<h:form id="formBotoesCor" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarCor" value="#{rsc.label_criar}"
					rendered="#{p:ifGranted('CRIAR_COR')}" styleClass="botao"
					action="#{manterCorBean.criarEntidade}" ajax="false"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterCorBean.preRenderList}" />
		<h:form id="formListCores" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">

				<p:panelGrid columns="3">
					<p:outputLabel value="#{rsc.label_cor} " for="acCor" />

					<p:outputLabel value="#{rsc.label_ativo}" for="chkAtivo" />

					<p:spacer />

					<p:autoComplete id="acCor" minQueryLength="3" size="40"
						value="#{manterCorBean.filtro.nome}" effect="fade" maxResults="7"
						completeMethod="#{manterCorBean.autoCompleteNome}">
						<p:ajax event="change" listener="#{manterCorBean.buscarPorNome}"
							update="listaCores" />
					</p:autoComplete>

					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterCorBean.filtro.ativo}" id="chkAtivo">
						<p:ajax event="change" listener="#{manterCorBean.buscarPorNome}"
							update="listaCores" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterCorBean.status}" var="c"
							itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listaCores"
						actionListener="#{manterCorBean.buscarPorNome}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>

			<p:watermark value="#{rsc.wm_nomeCorConsulta}" for="acCor" />

			<p:panel id="pnlListaCores" header="#{rsc.label_coresCadastradas}"
				toggleable="true" toggleSpeed="500">
				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="cor" id="listaCores" value="#{manterCorBean.entidades}"
						paginator="true" rows="10"
						paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">
						<p:column headerText="#{rsc.label_cor}" sortBy="#{cor.nome}">
							<p:outputLabel value="#{cor.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_ativo}" sortBy="#{cor.ativo}"
							styleClass="centralizado">
							<p:outputLabel value="#{rsc.label_sim}" rendered="#{cor.ativo}" />
							<p:outputLabel value="#{rsc.label_nao}" rendered="#{!cor.ativo}" />
						</p:column>

						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">
							<p:commandButton update=":habilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_COR') and !cor.ativo}"
								oncomplete="habilitar.show()" icon="ui-icon ui-icon-locked"
								title="#{rsc.label_habilitar}">
								<f:setPropertyActionListener value="#{cor}"
									target="#{manterCorBean.entidade}" />
							</p:commandButton>

							<p:commandButton update=":desabilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_COR') and cor.ativo}"
								oncomplete="desabilitar.show()" icon="ui-icon ui-icon-unlocked"
								title="#{rsc.label_desabilitar}">
								<f:setPropertyActionListener value="#{cor}"
									target="#{manterCorBean.entidade}" />
							</p:commandButton>


							<p:commandButton icon="ui-icon ui-icon-pencil"
								rendered="#{p:ifGranted('ALTERAR_COR')}"
								title="#{rsc.label_editar}" ajax="false" action="editarCor">
								<f:setPropertyActionListener value="#{cor}"
									target="#{manterCorBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
		</h:form>

		<p:confirmDialog message="#{msg.questionConfirmaHabilitar}"
			appendTo="@(body)" width="250" id="habilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="habilitar">
			<h:form id="habilitarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterCorBean.habilitar}" styleClass="botao"
					oncomplete="habilitar.hide()"
					update=":formListCores:listaCores, :growl" />
				<p:commandButton value="#{rsc.label_nao}" onclick="habilitar.hide()"
					styleClass="botao" />
			</h:form>
		</p:confirmDialog>

		<p:confirmDialog message="#{msg.questionConfirmaDesabilitar}"
			appendTo="@(body)" width="250" id="desabilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="desabilitar">
			<h:form id="desabilitarForm">
				<p:commandButton value="#{rsc.label_sim}" styleClass="botao"
					actionListener="#{manterCorBean.desabilitar}"
					oncomplete="desabilitar.hide()"
					update=":formListCores:listaCores, :growl" />
				<p:commandButton value="#{rsc.label_nao}"
					onclick="desabilitar.hide()" styleClass="botao" />
			</h:form>
		</p:confirmDialog>


	</ui:define>
</ui:composition>

